#!/bin/bash

if [[ $# -ne 4 ]] ; then 
   echo "check_users_custom -w <warning> -c <critical>"
   exit 3
fi

W=$2 # bad coding here -- i don't care.
C=$4 # we don't actually check for -w and -c

# all good after this
NUM=`who | awk ' { print $1 } ' | sort | uniq | wc -l`
VAR="";for i in `who | awk ' { print $1 } ' | sort | uniq` ; do j=`who | awk ' { print $1 } ' | grep $i | wc -l`; VAR="$VAR:$i,$j"; done ; VAR=`echo $VAR | cut -b 2-`
if [[ $NUM -lt $W ]] ; then
    echo "USERS_CUSTOM OK - ($NUM unique users)|$VAR"
    exit 0
fi
if [[ $NUM -lt $C ]]  ; then
    echo "USERS_CUSTOM WARN - ($NUM unique users)|$VAR"
    exit 1
fi

echo "USERS_CUSTOM CRIT - ($NUM unique users)|$VAR"
exit 2

